package com.pk.platform.business.common.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.pk.platform.business.common.dao.IClaDao;
import com.pk.platform.business.common.vo.ClaVO;
import com.pk.platform.business.core.dao.impl.GenericDaoImpl;
import com.pk.platform.domain.common.Cla;
import com.pk.platform.util.StringConverter;
import com.pk.platform.util.constant.Constant;
import com.pk.platform.util.page.ListPage;
import com.pk.platform.util.page.Pager;

public class ClaDaoImpl extends GenericDaoImpl implements IClaDao {

	public ListPage queryCla(ClaVO clavo, Pager pager) {
		StringBuffer sql = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		sql.append("select c.*, (select count(*) from child ch where ch.classId = c.id) as childCount from cla c where 1 = 1");
		if(StringConverter.isNotNull(clavo.getCla().getClassName()))
		{
			sql.append(" and c.className like ?");
			param.add("%" + clavo.getCla().getClassName() + "%");
		}
		if(StringConverter.isNotNull(clavo.getKindergartenId()))
		{
			sql.append(" and c.kgId = ?");
			param.add(clavo.getKindergartenId());
		}
		sql.append(this.getKgData("c", Constant.SQL));
		sql.append(" order by c.classType");
		return this.getListPage(sql.toString(), param.toArray(), pager);
	}
	
	public List<Cla> queryClassList(String kgId)
	{
		StringBuffer hql = new StringBuffer();
		hql.append("from Cla c where 1 = 1");
		List<Object> param = new ArrayList<Object>();
		if(StringConverter.isNotNull(kgId))
		{
			hql.append(" and c.kindergarten.id = ?");
			param.add(kgId);
		}
		hql.append(this.getKgData("c", Constant.HQL));
		hql.append(" order by c.classType");
		return this.getHibernateTemplate().find(hql.toString(), param.toArray());
	}

}
